package com.grwx.omc.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;


    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private LocalDateTime createTime;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long createUser;

    private LocalDateTime updateTime;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long updateUser;

    @TableLogic
    private Integer deleteFlag;

    public void preInsert() {
        this.id = IdWorker.getId();
        this.createTime = LocalDateTime.now();
        this.createUser = 0L;
        preUpdate();
        this.deleteFlag = 1;
    }

    public void preUpdate() {
        this.updateTime = LocalDateTime.now();
        this.updateUser = 0L;
    }
}
